package com.microsoft.mcp.sample.client;

import io.modelcontextprotocol.client.McpClient;
import io.modelcontextprotocol.client.McpSyncClient;
import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport;
import io.modelcontextprotocol.spec.McpClientTransport;
import io.modelcontextprotocol.spec.McpSchema;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.http.HttpClient;
import java.util.Map;


@Configuration
public class KnowledgeClient {

    @Bean
    public McpClientTransport mcpClientTransport(
            @Value("${mcp.server.url:http://localhost:8002/}") String serverUrl,
            @Value("${mcp.sse.endpoint:/sse/}") String sseEndpoint) {
        return HttpClientSseClientTransport.builder(serverUrl)
                .clientBuilder(HttpClient.newBuilder())
                .sseEndpoint(sseEndpoint)
                .build();
    }

    @Bean
    public McpSyncClient mcpBaseClient(McpClientTransport transport) {
        McpSyncClient client = McpClient.sync(transport).build();
        client.initialize();
        return client;
    }


}
